import time

from django.test import TestCase

from login_api.models import User


class UserModelTest(TestCase):

    def test_create_user(self):
        """
        创建用户
        """
        username = "cyaegha"+str(time.time())
        User.objects.create(username=username, password="123456", auth=User.AuthLevel.ROOT)
        self.assertTrue(User.objects.filter(username=username).exists())

    def test_registry_user_api(self):
        """
        注册接口
        """
        response = self.client.post('/api/registry')
        self.assertEqual(response.status_code, 200)

    def test_user_login_api(self):
        """
        登录接口
        """
        response = self.client.post('/api/login')
        self.assertEqual(response.status_code, 200)

    def test_user_info_api(self):
        """
        个人信息接口
        """
        response = self.client.post('/api/info')
        self.assertEqual(response.status_code, 200)
